package icu.qx.pbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.pbs.domain.PbsGroupType;
import icu.qx.pbs.service.IPbsGroupTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 班组类型Controller
 *
 * @author yong
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/pbs/groupType")
public class PbsGroupTypeController extends BaseController {
    @Autowired
    private IPbsGroupTypeService pbsGroupTypeService;

    /**
     * 查询班组类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PbsGroupType pbsGroupType) {
        startPage();
        List<PbsGroupType> list = pbsGroupTypeService.selectPbsGroupTypeList(pbsGroupType);
        return getDataTable(list);
    }

    /**
     * 查询班组类型列表
     */
    @GetMapping("/all")
    public AjaxResult all(PbsGroupType pbsGroupType) {
        List<PbsGroupType> list = pbsGroupTypeService.selectPbsGroupTypeList(pbsGroupType);
        return AjaxResult.success(list);
    }

    /**
     * 导出班组类型列表
     */
    @Log(title = "班组类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PbsGroupType pbsGroupType) {
        List<PbsGroupType> list = pbsGroupTypeService.selectPbsGroupTypeList(pbsGroupType);
        ExcelUtil<PbsGroupType> util = new ExcelUtil<PbsGroupType>(PbsGroupType.class);
        util.exportExcel(response, list, "班组类型数据");
    }

    /**
     * 获取班组类型详细信息
     */
    @GetMapping(value = "/{groupCode}")
    public AjaxResult getInfo(@PathVariable("groupCode") String groupCode) {
        return success(pbsGroupTypeService.selectPbsGroupTypeByGroupCode(groupCode));
    }

    /**
     * 新增班组类型
     */
    @Log(title = "班组类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PbsGroupType pbsGroupType) {
        return toAjax(pbsGroupTypeService.insertPbsGroupType(pbsGroupType));
    }

    /**
     * 修改班组类型
     */
    @Log(title = "班组类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PbsGroupType pbsGroupType) {
        return toAjax(pbsGroupTypeService.updatePbsGroupType(pbsGroupType));
    }

    /**
     * 删除班组类型
     */
    @Log(title = "班组类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{groupCodes}")
    public AjaxResult remove(@PathVariable String[] groupCodes) {
        return toAjax(pbsGroupTypeService.deletePbsGroupTypeByGroupCodes(groupCodes));
    }
}
